Problem 2
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.0 ──
## ✓ ggplot2 3.3.2 ✓ purrr 0.3.4
## ✓ tibble 3.0.4 ✓ dplyr 1.0.2
## ✓ tidyr 1.1.2 ✓ stringr 1.4.0
## ✓ readr 1.3.1 ✓ forcats 0.5.0
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(p8105.datasets)
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
data("rest_inspec")
Italian_rest=
rest_inspec %>%
filter(
grade %in% c("A", "B", "C"),
str_detect(cuisine_description, "Italian"),
boro != "0") %>%
relocate(boro) %>%
drop_na() %>%
sample_n(10000) %>%
view()
Scatterplot
Italian restaurant score across inspection date in the 5 boroughs
Italian_rest %>%
mutate(text_label = str_c("Score: ", score, "\nGrade: ", grade)) %>%
plot_ly(
x = ~inspection_date, y = ~score, type = "scatter", mode = "markers",
color = ~boro, text = ~text_label, alpha = 0.8)
Boxplot
Distribution of health scores for Italian restaurants by boro
Italian_rest %>%
plot_ly(y = ~score, color = ~boro, type = "box", colors = "viridis")
Bar Chart
Number of Italian restaurants inspected per boro
Italian_rest %>%
count(boro) %>%
mutate(boro = fct_reorder(boro, n)) %>%
plot_ly(x = ~boro, y = ~n, color = ~boro, type = "bar", colors = "viridis", showlegend = FALSE)